Open
Conversation
Instead of converting a path to an open file, getting the file name, closing it again, and then opening it again, just use the given name. Sometimes simplicity is better. And it will let us use run repl in a future commit.
This allows starting slots and other builtins like the REPL.
dlech
reviewed
Aug 5, 2025
| with _get_script_path(args.file) as script_path: | ||
| mpy = await compile_multi_file(script_path, args.abi) | ||
| if args.file == "-": | ||
| with NamedTemporaryFile(suffix=".py", delete=False) as temp: |
Member
There was a problem hiding this comment.
Would be best to eventually delete the temporary file. A contextlib.ExitStack would be the simplest way to do this.
| else: | ||
| # If using stdin, save to temporary file first. | ||
| if args.file == "-": | ||
| with NamedTemporaryFile(suffix=".py", delete=False) as temp: |
| metavar="<file>", | ||
| help="path to a MicroPython script or `-` for stdin", | ||
| type=argparse.FileType(), | ||
| help="path to a MicroPython script, `-` for stdin, or `repl` for interactive prompt", |
Member
There was a problem hiding this comment.
Might as well allow this to take a number to run programs in an existing slot as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes it possible to start the REPL with pybricksdev.
It isn't very useful though since
stdinisn't forwarded to the hub yet.